package com.bjsxt.controller.erp;

import com.bjsxt.aspectj.annotation.Log;
import com.bjsxt.aspectj.enums.BusinessType;
import com.bjsxt.controller.BaseController;
import com.bjsxt.domain.Producter;
import com.bjsxt.dto.ProducterDto;
import com.bjsxt.service.ProducterService;
import com.bjsxt.utils.ShiroSecurityUtils;
import com.bjsxt.vo.AjaxResult;
import com.bjsxt.vo.DataGridView;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.apache.dubbo.config.annotation.Reference;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author:liao
 * @Description:TODO
 * @date:2020/12/20
 */
@RestController
@RequestMapping("erp/producter")
public class ProducterController extends BaseController {

    @Reference // 远程调用
    private ProducterService producterService;

    //分页查询
    @GetMapping("listProducterForPage")
    @HystrixCommand
    public AjaxResult listProducterForPage(ProducterDto producterDto){
        DataGridView dataGridView = producterService.listProducterPage(producterDto);
        return AjaxResult.success("查询成功",dataGridView.getData(),dataGridView.getTotal());
    }

    //增加
    @PostMapping("addProducter")
    @HystrixCommand
    @Log(title = "增加生产厂家信息",businessType = BusinessType.INSERT)
    public AjaxResult addProducter(@Validated ProducterDto producterDto){
        producterDto.setSimpleUser(ShiroSecurityUtils.getCurrentSimpleUser());
        return AjaxResult.toAjax(producterService.insertProducter(producterDto));
    }

    //修改
    @PutMapping("updateProducter")
    @HystrixCommand
    @Log(title = "修改生产厂家信息",businessType = BusinessType.UPDATE)
    public AjaxResult updateProducter(@Validated ProducterDto producterDto){
        producterDto.setSimpleUser(ShiroSecurityUtils.getCurrentSimpleUser());
        return AjaxResult.toAjax(producterService.updateProducter(producterDto));
    }

    // 删除
    @DeleteMapping("deleteProducterByIds/{producterIds}")
    @Log(title = "删除生产厂家信息",businessType = BusinessType.DELETE)
    @HystrixCommand
    public AjaxResult deleteProducterByIds( @PathVariable Long[] producterIds){
        return AjaxResult.toAjax(producterService.deleteProducter(producterIds));
    }

    // 根据id查询生产厂家信息
    @GetMapping("getProducterById/{producterId}")
    @HystrixCommand
    public AjaxResult getProducterById(@PathVariable Long producterId){
        return AjaxResult.success(producterService.getOne(producterId));
    }

    // 查询有效的生产厂家信息
    @GetMapping("selectAllProducter")
    @HystrixCommand
    public AjaxResult selectAllProducter(){
        return AjaxResult.success(producterService.selectAllProducter());
    }


}
